From 430bd187998fa624a3b4d7ab56317993f92f149d Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Mon, 12 Aug 2024 06:37:08 -0600 Subject: [PATCH] correct simplify filter with maximum allowable error option and the metric being overall route length or relative error (#1316) * add test for simplify w/ relative+error opts. * fix simplify filter error+length operation. * fix simplify relative+error * remove debug statement * simplify error unit tests and documentation. * format parse, update includes. * prune redundant test case --- parse.cc | 17 +- reference/simplify_error_length.gpx | 206 +++++++++++----------- smplrout.cc | 32 ++-- testo.d/simplify-relative.test | 3 + testo.d/simplify.test | 7 +- xmldoc/filters/options/simplify-error.xml | 3 +- 6 files changed, 143 insertions(+), 125 deletions(-) diff --git a/parse.cc b/parse.cc index 5dacd5016..b14c27227 100644 --- a/parse.cc +++ b/parse.cc @@ -20,11 +20,15 @@ */ -#include "defs.h" -#include "jeeps/gpsmath.h" -#include -#include -#include //strtod +#include // for isspace +#include // for fabs +#include // for sscanf +#include // for strtod + +#include // for QString + +#include "defs.h" // for case_ignore_strcmp, fatal, KPH_TO_MPS, MPH_TO_MPS, warning, FEET_TO_METERS, KNOTS_TO_MPS, CSTR, FATHOMS_TO_METERS, MILES_TO_METERS, NMILES_TO_METERS, kDatumWGS84, grid_type, parse_coordinates, parse_distance, parse_speed, grid_bng, grid_lat_lon_ddd, grid_lat_lo... +#include "jeeps/gpsmath.h" // for GPS_Math_Known_Datum_To_WGS84_M, GPS_Math_Swiss_EN_To_WGS84, GPS_Math_UKOSMap_To_WGS84_H, GPS_Math_UTM_EN_To_Known_Datum /* * parse_distance: @@ -83,7 +87,8 @@ parse_distance(const char* str, double* val, double scale, const char* module) } int -parse_distance(const QString& str, double* val, double scale, const char* module) { +parse_distance(const QString& str, double* val, double scale, const char* module) +{ return parse_distance(CSTR(str), val, scale, module); } diff --git a/reference/simplify_error_length.gpx b/reference/simplify_error_length.gpx index 48a4357ab..2ba09ce7a 100644 --- a/reference/simplify_error_length.gpx +++ b/reference/simplify_error_length.gpx @@ -1,7 +1,7 @@ - + LAP001 LAP001 @@ -34,6 +34,16 @@ 3.088000 + + 510.200 + + 5.925000 + + + 510.200 + + 6.637000 + 511.400 @@ -151,6 +161,11 @@ 6.169000 + + 519.200 + + 6.248000 + 520.400 @@ -251,11 +266,6 @@ 7.546000 - - 540.800 - - 8.935000 - 538.600 @@ -281,6 +291,11 @@ 4.329000 + + 536.600 + + 5.039000 + 536.600 @@ -306,6 +321,11 @@ 8.963000 + + 538.600 + + 8.420000 + 538.600 @@ -336,10 +356,10 @@ 7.927000 - + 536.400 - - 8.233000 + + 8.272000 536.400 @@ -371,11 +391,6 @@ 8.439000 - - 538.800 - - 8.476000 - 538.800 @@ -516,11 +531,6 @@ 5.373000 - - 541.600 - - 6.961000 - 537.200 @@ -646,16 +656,6 @@ 6.347000 - - 533.600 - - 6.408000 - - - 533.600 - - 6.192000 - 538.400 @@ -720,6 +720,16 @@ 7.587000 + + 542.000 + + 6.804000 + + + 542.000 + + 6.545000 + 543.200 @@ -755,10 +765,10 @@ 5.492000 - - 543.000 - - 7.660000 + + 544.000 + + 7.097000 542.200 @@ -815,6 +825,11 @@ 4.790000 + + 521.400 + + 4.333000 + 520.000 @@ -850,6 +865,11 @@ 5.026000 + + 520.000 + + 6.505000 + 520.000 @@ -950,6 +970,16 @@ 8.019000 + + 526.400 + + 1.765000 + + + 526.400 + + 1.335000 + @@ -1068,16 +1098,6 @@ 7.009000 - - 535.400 - - 6.641000 - - - 539.400 - - 6.555000 - 542.400 @@ -1088,6 +1108,11 @@ 5.426000 + + 543.800 + + 5.012000 + 548.000 @@ -1118,21 +1143,6 @@ 11.715000 - - 540.800 - - 10.787000 - - - 540.000 - - 10.409000 - - - 539.000 - - 10.124000 - 538.600 @@ -1198,11 +1208,6 @@ 10.073000 - - 536.400 - - 10.149000 - 535.400 @@ -1223,11 +1228,6 @@ 7.019000 - - 532.000 - - 7.612000 - 532.000 @@ -1313,11 +1313,6 @@ 9.152000 - - 529.600 - - 9.009000 - 529.600 @@ -1348,6 +1343,16 @@ 6.158000 + + 527.600 + + 6.444000 + + + 527.600 + + 6.139000 + 527.600 @@ -1383,6 +1388,11 @@ 6.457000 + + 529.600 + + 7.202000 + 529.600 @@ -1403,11 +1413,6 @@ 8.735000 - - 528.200 - - 9.047000 - 527.800 @@ -1448,6 +1453,11 @@ 6.894000 + + 521.000 + + 8.741000 + 521.000 @@ -1478,11 +1488,6 @@ 6.483000 - - 521.000 - - 8.439000 - 521.000 @@ -1508,6 +1513,11 @@ 6.395000 + + 525.200 + + 7.643000 + 525.200 @@ -1553,26 +1563,11 @@ 5.394000 - - 533.600 - - 6.307000 - - - 536.400 - - 5.016000 - 539.400 4.804000 - - 540.200 - - 4.605000 - 540.200 @@ -1583,6 +1578,16 @@ 4.724000 + + 542.400 + + 4.880000 + + + 542.400 + + 5.821000 + 542.400 @@ -1593,11 +1598,6 @@ 6.516000 - - 542.400 - - 6.389000 - 542.400 diff --git a/smplrout.cc b/smplrout.cc index 5570991d7..6a71295b3 100644 --- a/smplrout.cc +++ b/smplrout.cc @@ -57,7 +57,7 @@ */ #include -#include // for strtol +#include // for strtod, strtol #include // for prev #include // for QDateTime @@ -103,12 +103,12 @@ double SimplifyRouteFilter::compute_track_error(const neighborhood& nb) const break; case metric_t::length: track_error = radtomiles( - gcdist(wpt1->latitude, wpt1->longitude, - wpt3->latitude, wpt3->longitude) + - gcdist(wpt3->latitude, wpt3->longitude, - wpt2->latitude, wpt2->longitude) - - gcdist(wpt1->latitude, wpt1->longitude, - wpt2->latitude, wpt2->longitude)); + gcdist(RAD(wpt1->latitude), RAD(wpt1->longitude), + RAD(wpt3->latitude), RAD(wpt3->longitude)) + + gcdist(RAD(wpt3->latitude), RAD(wpt3->longitude), + RAD(wpt2->latitude), RAD(wpt2->longitude)) - + gcdist(RAD(wpt1->latitude), RAD(wpt1->longitude), + RAD(wpt2->latitude), RAD(wpt2->longitude))); break; case metric_t::relative: default: // eliminate false positive warning with g++ 11.3.0: ‘error’ may be used uninitialized in this function [-Wmaybe-uninitialized] @@ -125,8 +125,8 @@ double SimplifyRouteFilter::compute_track_error(const neighborhood& nb) const wpt2->latitude, wpt2->longitude, frac, &reslat, &reslon); track_error = radtometers(gcdist( - wpt3->latitude, wpt3->longitude, - reslat, reslon)); + RAD(wpt3->latitude), RAD(wpt3->longitude), + RAD(reslat), RAD(reslon))); } else { // else distance to connecting line track_error = radtometers(linedist( wpt1->latitude, wpt1->longitude, @@ -297,11 +297,15 @@ void SimplifyRouteFilter::init() count = strtol(countopt, nullptr, 10); break; case limit_basis_t::error: { - int res = parse_distance(erroropt, &error, 1.0, MYNAME); - if (res == 0) { - error = 0; - } else if (res == 2) { /* parameter with unit */ - error = METERS_TO_MILES(error); + if (metric == metric_t::relative) { + error = strtod(erroropt, nullptr); + } else { + int res = parse_distance(erroropt, &error, 1.0, MYNAME); + if (res == 0) { + error = 0; + } else if (res == 2) { /* parameter with unit */ + error = METERS_TO_MILES(error); + } } } break; diff --git a/testo.d/simplify-relative.test b/testo.d/simplify-relative.test index cb39a2e7f..3286faa2b 100644 --- a/testo.d/simplify-relative.test +++ b/testo.d/simplify-relative.test @@ -4,3 +4,6 @@ gpsbabel -i gpx -f ${REFERENCE}/track/simplify-relative.gpx -x simplify,relative,count=33 -o gpx -F ${TMPDIR}/simplify-relative2.gpx compare ${REFERENCE}/track/simplify-relative2.gpx ${TMPDIR}/simplify-relative2.gpx +gpsbabel -i gpx -f ${REFERENCE}/track/simplify-relative.gpx -x simplify,relative,error=0.61 -o gpx -F ${TMPDIR}/simplify-relative3.gpx +compare ${REFERENCE}/track/simplify-relative2.gpx ${TMPDIR}/simplify-relative3.gpx + diff --git a/testo.d/simplify.test b/testo.d/simplify.test index 7771702bb..6429f9028 100644 --- a/testo.d/simplify.test +++ b/testo.d/simplify.test @@ -19,7 +19,12 @@ gpsbabel -i gpx -f ${REFERENCE}/track/garmin-edge-800-output.gpx \ compare ${REFERENCE}/simplify_error_crosstrack.gpx ${TMPDIR}/simplify_error.gpx gpsbabel -i gpx -f ${REFERENCE}/track/garmin-edge-800-output.gpx \ - -x simplify,error=1000m,length \ + -x simplify,error=20.34m,length \ -o gpx -F ${TMPDIR}/simplify_error_length.gpx compare ${REFERENCE}/simplify_error_length.gpx ${TMPDIR}/simplify_error_length.gpx +# check default error units are miles +gpsbabel -i gpx -f ${REFERENCE}/track/garmin-edge-800-output.gpx \ + -x simplify,error=0.01263869,length \ + -o gpx -F ${TMPDIR}/simplify_error_length_miles.gpx +compare ${REFERENCE}/simplify_error_length.gpx ${TMPDIR}/simplify_error_length_miles.gpx diff --git a/xmldoc/filters/options/simplify-error.xml b/xmldoc/filters/options/simplify-error.xml index 4e6a18417..8d7e8e5e8 100644 --- a/xmldoc/filters/options/simplify-error.xml +++ b/xmldoc/filters/options/simplify-error.xml @@ -3,7 +3,8 @@ This option specifies the maximum allowable error that may be introduced by removing a single point. Used with the and methods, the value of this option is a distance, specified in miles by default. You may also specify the distance in -kilometers by adding a 'k' to the end of the number. +kilometers by adding a 'k' to the end of the number, meters by adding a 'm', or +feet by adding 'ft'. For the method it is a dimensionless quantity. -- 2.30.2